<template>
  <div class="fly-con">
    <div class="fly-layer_title">
      <span>漫游设置</span>
    </div>
    <div class="fly_close" @click="doCloseFlyPopup"></div>
    <div class="fly-control-con">
      <div class="select_fly">
        <el-select v-model="value" placeholder="请选择" style="width:220px" size="small">
          <el-option
            v-for="(item, index) in options"
            :key="index"
            :label="item.label"
            :value="item.data"
          ></el-option>
        </el-select>
      </div>

      <div class="btnClass" @click="startFly2(value)" v-if="btntype == 2">
        <span>开始飞行</span>
      </div>
      <div class="btnClass" @click="exitFly2()" v-if="btntype == 2">
        <span>退出飞行</span>
      </div>
      <div class="btnClass" @click="startFly3(value)" v-if="btntype == 3">
        <span>开始飞行</span>
      </div>
      <div class="btnClass" @click="exitFly3()" v-if="btntype == 3">
        <span>退出飞行</span>
      </div>
      <!-- <button @click="initFly()">初始化飞行</button>
            <button @click="startFly()">开始飞行</button>
            <button @click="stopFly()">停止飞行</button>

            <button @click="continueFly()">继续飞行</button>
      <button @click="exitFly()">退出飞行</button>-->

      <!-- <div class="btnClass" @click="initFly()">
                <span>初始化飞行</span>
      </div>-->

      <!-- <div class="btnClass" @click="stopFly()" v-if="flyStatus == 1">
                <span>暂停飞行</span>
            </div>
            <div class="btnClass" @click="continueFly()" v-if="flyStatus == 2">
                <span>继续飞行</span>
      </div>-->

      <!-- <div class="fly-control-btn">
                <div class="start-fly" @click="doStartFly">
                    <img :src="require('@/assets/toolbarPopup/start-fly.png')" height="32" width="32"/>
                    <span >开始</span>
                </div>
                <div class="stop-fly" @click="doStopFly">
                    <img :src="require('@/assets/toolbarPopup/stop-fly.png')"  height="32" width="32"/>
                    <span >停止</span>
                </div>
            </div>
      <el-slider label="漫游速度" v-model="flySpeed" show-input  @change="changeFlySpeed($event)"></el-slider>-->
    </div>
  </div>
</template>

<script>
import Bus from "@/js/EventBus";
import {
  getMyLineData,
  getDLineData,
  getBoxLineData,
  getmanyouData,
} from "@/api/http";

// import manyou from "@/js/manyou.json";
export default {
  name: "MarkerPopup",

  data() {
    return {
      selectShow: false,
      flySpeed: 0,
      flyStatus: 0, // 0:开始飞行， 1：暂停，2：继续，
      options: [],
      value: "",
      btntype: 2,
    };
  },
  created() {
    let btntype = window.sessionStorage.getItem("btntype");
    if (btntype) {
      this.btntype = btntype;
    }
  },
  mounted() {
    // this.initFly();
    Bus.$on("btntype", (e) => {
      this.btntype = e;
      this.value = "";
    });
    Bus.$on("initmanyou", () => {
      this.options = [];
      this.value = "";
      this.getflydata();
    });
    this.getflydata();
  },
  computed: {},
  watch: {
    value: {
      handler(newval, oldval) {
        // console.log(newval, "newval");
        this.$store.commit("changemanyoudata", newval);
      },
      deep: true,
    },

    // Thematiclayer: {
    //   handler(newval, oldval) {
    //     // console.log(newval, "newval");
    //     // this.$store.commit("changemanyoudata", newval);
    //     this.getflydata();
    //   },
    //   deep: true,
    // },
  },

  methods: {
    async getflydata() {
      const data = await getmanyouData();
      // const data = await getMyLineData([1, 2]);
      console.log(data);
      // data.features.forEach((element) => {
      //   this.options.push({
      //     label: element.name,
      //     data: element.array_to_string,
      //   });
      // });

      var showarr = [];
      this.Thematiclayer.forEach((item) => {
        if (item.type == "line" && item.show == true) {
          showarr.push(item.grade);
        }
      });
      // console.log(showarr,"showarr")
      console.log(this.Thematiclayer);
      // console.log(manyou.features, "manyou");
      data.features.forEach((element) => {
        showarr.forEach((e) => {
          console.log(e);
          if (element.properties.grade == e) {
            this.options.push({
              label: element.properties.name,
              data: element.geometry.coordinates[0],
            });
          }
        });

        // this.options.push({
        //   label: element.properties.name,
        //   data: element.geometry.coordinates,
        // });
      });
    },
    async startFly2(e) {
      let idlist = e.split(",");
      var arr = [];
      for (let index = 0; index < idlist.length; index++) {
        const element = idlist[index];
        const res = await getBoxLineData(`UserID='${element}'`);
        arr.push(res.features[0].geometry.coordinates[0]);
      }
      Bus.$emit("startFly2", arr.flat());
    },
    exitFly2() {
      Bus.$emit("exitFly2", false);
    },

    async startFly3(e) {
      // console.log(e, "3============");
      // let idlist = e.split(",");
      // var arr = [];
      // for (let index = 0; index < idlist.length; index++) {
      //   const element = idlist[index];
      //   const res = await getBoxLineData(`UserID='${element}'`);
      //   arr.push(res.features[0].geometry.coordinates[0]);
      // }
      // console.log(arr.flat());
      // Bus.$emit("startFly3", arr.flat());
      Bus.$emit("startFly3", e);
    },
    exitFly3() {
      Bus.$emit("exitFly3", false);
    },

    changeFlySpeed(value) {
      console.log("==changeHeightValue===", value);
    },

    doStartFly() {
      console.log("==doStartFly===");
    },

    doStopFly() {
      console.log("==doStopFly===");
    },
    doCloseFlyPopup() {
      this.$parent.doSetIsShowPopup();
    },
    // initFly() {
    //   Bus.$emit("initFly", 0);
    // },
    startFly() {
      Bus.$emit("initFly" + this.btntype, 1);
      this.flyStatus = 1;
    },
    // stopFly() {
    //   Bus.$emit("initFly", 2);
    //   this.flyStatus = 2;
    // },
    // continueFly() {
    //   Bus.$emit("initFly", 3);
    //   this.flyStatus = 1;
    // },
    exitFly() {
      Bus.$emit("initFly" + this.btntype, 4);
      this.flyStatus = 0;
    },
  },
};
</script>

<style lang="scss" scoped>
.fly-con {
  z-index: 999 !important;
  /* // width: 301px;
        // color: #ffffff;
        // background: url("../assets/panelTree/dtml_bg.png") no-repeat;
        // background-size: 100% 100%; */
}

.fly-layer_title {
  width: 280px;
  height: 35px;
  box-sizing: border-box;
  background: url("@/assets/panelTree/dtml_bg_title.png") no-repeat;
  font-family: SourceHanSansCN-Regular;
  font-size: 18px;
  background-size: 90% 100%;
  text-align: left;
  padding-left: 50px;
  line-height: 40px;
  /* // background-color: red; */
  margin: 10px 0 0 10px;
}

.fly-layer_title span {
  font-family: SourceHanSansCN-Regular;
  font-size: 14px;
  color: #c8e9ff;
}

.fly_close {
  width: 14px;
  height: 15px;
  background: url("@/assets/poipopup/poi_popup_close.png");
  position: relative;
  top: -26px;
  left: 240px;
  cursor: pointer;
}

.fly-control-con {
  width: 90%;
  /* // background-color: red; */
  margin: 0 auto;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  padding-bottom: 20px;

  .fly-control-btn {
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 10px 0;

    .start-fly {
      cursor: pointer;
    }

    .stop-fly {
      cursor: pointer;
    }

    .start-fly span,
    .stop-fly span {
      font-family: SourceHanSansCN-Regular;
      font-size: 14px;
      font-weight: normal;
      font-stretch: normal;
      line-height: 44px;
      letter-spacing: 0px;
      color: #daf0ff;
    }
  }

  .btnClass {
    width: 100px;
    height: 28px;
    background: url("@/assets/panelTree/btn-uncheck.png");
    text-align: center;
    margin: 10px 0 0 10px;
    cursor: pointer;

    span {
      font-family: SourceHanSansCN-Medium;
      font-size: 12px;
      font-weight: normal;
      font-stretch: normal;
      line-height: 28px;
      letter-spacing: 1px;
      /* color: #00baff; */
      color: #b9ddf5;
    }
  }
}
.select_fly {
  padding-left: 10px;
}
</style>
